import numpy as np


def calculate_angle_rad_begin_to_M(begin_x,begin_y,M_x,M_y):

    if M_x>begin_x and M_y>=begin_y: #第一象限
        angle_rad = (np.atan((M_y - begin_y) / (M_x - begin_x)))
    elif M_x>begin_x and M_y<begin_y: #第四象限
        angle_rad = (np.atan((M_y - begin_y) / (M_x - begin_x)))

    if M_x<begin_x and M_y>=begin_y: #第二象限
        angle_rad = (np.atan((M_y - begin_y) / (M_x - begin_x))) + np.pi
    elif M_x<begin_x and M_y<begin_y: #第三象限
        angle_rad = (np.atan((M_y - begin_y) / (M_x - begin_x))) - np.pi

    if M_x==begin_x and M_y>begin_y: #y轴正半轴
        angle_rad = (np.pi)/2

    if M_x==begin_x and M_y<begin_y: #y轴负半轴
        angle_rad = -(np.pi)/2

    #if M_x==begin_x and M_y==begin_y: #y轴负半轴
    #    angle_rad = 0

    return angle_rad